package com.niiwoo.civet.account.service.dubbo.trade;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.niiwoo.civet.account.dto.request.ReceivedRepaymentSuccessAccountingRequestDTO;
import com.niiwoo.civet.account.dto.request.TransFreezeRequestDTO;
import com.niiwoo.civet.account.dto.request.TransUnfreezeRequestDTO;
import com.niiwoo.civet.account.dto.response.OrderSuccessAccountingResponseDTO;
import com.niiwoo.civet.account.dto.response.TransFreezeResponseDTO;
import com.niiwoo.civet.account.dto.response.TransUnfreezeResponseDTO;
import com.niiwoo.civet.account.enums.OrderTypeEnum;
import com.niiwoo.civet.account.service.local.trade.TransOrderFacade;
import com.niiwoo.civet.account.service.trade.TransOrderDubboService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by wangjichao on 2018/4/20.
 */

@Service(version = "1.0.0")
@Slf4j
public class TransOrderDubboServiceImpl implements TransOrderDubboService{

    @Autowired
    TransOrderFacade transOrderFacade;

    @Override
    public TransFreezeResponseDTO refundFreeze(TransFreezeRequestDTO requestDTO) {
        log.info("交易冻结请求DUBBO层入参:{}", JSON.toJSONString(requestDTO));
        TransFreezeResponseDTO responseDTO = transOrderFacade.refundFreeze(requestDTO);
        log.info("交易冻结请求DUBBO层返回:{}", JSON.toJSONString(responseDTO));
        return responseDTO;
    }

    @Override
    public TransUnfreezeResponseDTO transUnfreeze(TransUnfreezeRequestDTO requestDTO) {
        log.info("交易解冻请求DUBBO层入参:{}", JSON.toJSONString(requestDTO));
        TransUnfreezeResponseDTO responseDTO = transOrderFacade.transUnfreeze(requestDTO);
        log.info("交易解冻请求DUBBO层返回:{}", JSON.toJSONString(responseDTO));
        return responseDTO;
    }

    @Override
    public TransFreezeResponseDTO queryTransFreeze(Long orderId, OrderTypeEnum orderType) {
        log.info("交易冻结查询请求DUBBO层入参:orderId:{},orderType:{}",orderId,orderType.getCode());
        TransFreezeResponseDTO responseDTO = transOrderFacade.queryTransFreeze(orderId,orderType);
        log.info("交易冻结查询请求DUBBO层返回:{}", JSON.toJSONString(responseDTO));
        return responseDTO;
    }

    @Override
    public OrderSuccessAccountingResponseDTO receivedRepaymentSuccessAccounting(ReceivedRepaymentSuccessAccountingRequestDTO requestDTO) {
        log.info("回款成功记账请求DUBBO层入参:{}", JSON.toJSONString(requestDTO));
        OrderSuccessAccountingResponseDTO responseDTO = transOrderFacade.receivedRepaymentSuccessAccounting(requestDTO);
        log.info("回款成功记账请求DUBBO层返回:{}", JSON.toJSONString(responseDTO));
        return responseDTO;
    }

    @Override
    public OrderSuccessAccountingResponseDTO repaymentSuccessAccounting(String freezeRequestNo) {
        log.info("还款成功记账请求DUBBO层入参:{}", freezeRequestNo);
        OrderSuccessAccountingResponseDTO responseDTO = transOrderFacade.repaymentSuccessAccounting(freezeRequestNo);
        log.info("还款成功记账请求DUBBO层返回:{}", JSON.toJSONString(responseDTO));
        return responseDTO;
    }

    @Override
    public void transFreezeResultCheckJob() {
        log.info("交易冻结补单JOB_DUBBO层开始");
        transOrderFacade.transFreezeResultCheckJob();
        log.info("交易冻结补单JOB_DUBBO层结束");
    }

    @Override
    public void transUnfreezeResultCheckJob() {
        log.info("交易解冻补单JOB_DUBBO层开始");
        transOrderFacade.transUnfreezeResultCheckJob();
        log.info("交易解冻补单JOB_DUBBO层结束");
    }
}
